using System;
using System.Collections.Generic;
using System.Text;
using Yorrick.FlickrMetadataSynchr.Match;
using Yorrick.FlickrMetadataSynchr.Sync;

namespace Yorrick.FlickrMetadataSynchr.Data
{
    /// <summary>
    /// Static class with methods that can be used as delegates for getting metadata fields
    /// from <see cref="PictureMetadata"/> instances.
    /// </summary>
    internal static class MetadataDelegates
    {
        /// <summary>
        /// Gets the date taken.
        /// </summary>
        /// <param name="pictureMetadata">A <see cref="PictureMetadata"/> instance.</param>
        /// <returns>The date taken.</returns>
        public static DateTime GetDateTaken(PictureMetadata pictureMetadata)
        {
            return pictureMetadata.DateTaken;
        }

        /// <summary>
        /// Gets the file name without extension.
        /// </summary>
        /// <param name="localPictureMetadata">A <see cref="LocalPictureMetadata"/> instance.</param>
        /// <returns>The file name without extension.</returns>
        public static string GetFileNameWithoutExtension(LocalPictureMetadata localPictureMetadata)
        {
            return localPictureMetadata.FileNameWithoutExtension;
        }

        /// <summary>
        /// Gets the title.
        /// </summary>
        /// <param name="pictureMetadata">A <see cref="PictureMetadata"/> instance.</param>
        /// <returns>The title.</returns>
        public static string GetTitle(PictureMetadata pictureMetadata)
        {
            return pictureMetadata.Title;
        }

        /// <summary>
        /// Gets the Flickr id from a local picture or <c>null</c> if it doesn't have any.
        /// </summary>
        /// <param name="localPictureMetadata"></param>
        /// <returns>The Flickr id or <c>null</c> if it doesn't have any.</returns>
        public static string GetFlickrId(LocalPictureMetadata localPictureMetadata)
        {
            return localPictureMetadata.FlickrId;
        }

        /// <summary>
        /// Gets the Flickr id.
        /// </summary>
        /// <param name="flickrPictureMetadata">A <see cref="FlickrPictureMetadata"/> instance.</param>
        /// <returns>The Flickr id.</returns>
        public static string GetFlickrId(FlickrPictureMetadata flickrPictureMetadata)
        {
            return flickrPictureMetadata.FlickrId;
        }

        /// <summary>
        /// Gets a combined match key for a Flickr picture based on date taken and title.
        /// </summary>
        /// <param name="flickrPictureMetadata">Metadata for the Flickr picture.</param>
        /// <returns>The combined match key.</returns>
        public static DateTakenTitleMatchKey GetFlickrDateTakenTitleMatchKey(FlickrPictureMetadata flickrPictureMetadata)
        {
            return new DateTakenTitleMatchKey(flickrPictureMetadata.DateTaken, flickrPictureMetadata.Title);
        }

        /// <summary>
        /// Gets a combined match key for a local picture based on date taken and filename.
        /// </summary>
        /// <param name="localPictureMetadata">Metadata for the local picture.</param>
        /// <returns>The combined match key.</returns>
        public static DateTakenTitleMatchKey GetLocalDateTakenTitleMatchKey(LocalPictureMetadata localPictureMetadata)
        {
            return new DateTakenTitleMatchKey(localPictureMetadata.DateTaken, localPictureMetadata.FileNameWithoutExtension);
        }

        /// <summary>
        /// Determines if a string match key should be ignored.
        /// </summary>
        /// <param name="key">The match key to evaluate.</param>
        /// <returns><c>True</c> if the key should be ignored, <c>false</c> otherwise.</returns>
        public static bool IsNullMatchKey(string key)
        {
            return String.IsNullOrEmpty(key);
        }

        /// <summary>
        /// Determines if a <see cref="DateTime"/> match key should be ignored.
        /// </summary>
        /// <param name="dateTaken">The match key to evaluate.</param>
        /// <returns><c>True</c> if the key should be ignored, <c>false</c> otherwise.</returns>
        public static bool IsNullMatchKey(DateTime dateTaken)
        {
            return dateTaken.Equals(DateTime.MinValue);
        }

        /// <summary>
        /// Determines if a combined match key should be ignored.
        /// </summary>
        /// <param name="key">The match key to evaluate.</param>
        /// <returns><c>True</c> if the key should be ignored, <c>false</c> otherwise.</returns>
        public static bool IsNullMatchKey(DateTakenTitleMatchKey key)
        {
            return key.Equals(default(DateTakenTitleMatchKey));
        }
    }
}
